import type { VbenFormSchema } from '@vben/common-ui';

import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { DictApi, DVMTAPI } from '#/api';

import { reactive } from 'vue';

import { DictResp } from '#/api';

const sys_yes_no = reactive<DictApi.SelectOption[]>([]);

DictResp(['sys_yes_no']).then((res) => {
  // 将两个数组合并
  if (res.sys_yes_no) {
    sys_yes_no.push(...res.sys_yes_no);
  }
});
export function useSearchForm(): VbenFormSchema[] {
  return [
    {
      component: 'Input',
      componentProps: {
        placeholder: '请输入设备类型名称',
        class: 'mr-5',
      },
      fieldName: 'machineryTypeName',
      label: '类型名称',
      labelClass: 'text-[#606266] font-bold',
    },
    {
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: sys_yes_no,
        placeholder: '选择是或否',
      },
      fieldName: 'enableFlag',
      label: '是否启用',
      labelClass: 'text-[#606266] font-bold',
    },
  ];
}
export function useColumns(): VxeTableGridOptions<DVMTAPI.Datum>['columns'] {
  return [
    {
      align: 'left',
      field: 'machineryTypeCode',
      fixed: 'left',
      title: '设备类型编码',
      treeNode: true,
    },
    {
      field: 'machineryTypeName',
      title: '设备类型名称',
    },
    {
      align: 'center',
      cellRender: { name: 'CellTag' },
      field: 'enableFlag',
      title: '是否启用',
    },

    {
      align: 'center',
      field: 'remark',
      title: '备注',
    },

    {
      align: 'center',
      field: 'operation',
      fixed: 'right',
      slots: { default: 'action' },
      headerAlign: 'center',
      showOverflow: false,
      title: '操作',
      width: 200,
    },
  ];
}
